package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.SmallViSdeosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author maorf
 * @version 1.0
 */
@RestController
@RequestMapping("smallVideos")
public class SmallVideoController {
    @Autowired
    private SmallViSdeosService smallVideosService;

    @PostMapping
    public ResponseEntity saveVideos(MultipartFile videoFile,MultipartFile videoThumbnail) throws IOException {
        smallVideosService.upload(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

    //小视频列表
    @GetMapping
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "5") Integer pagesize){
        PageResult pageResult = smallVideosService.getSmallVideos(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @PostMapping("/{id}/userFocus")
    public ResponseEntity userFocus(@PathVariable("id") Long followUserId) {
        smallVideosService.userFocus(followUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 取消关注视频作者
     */
    @PostMapping("/{id}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("id") Long followUserId) {
        smallVideosService.userUnFocus(followUserId);
        return ResponseEntity.ok(null);
    }


}
